﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:ctlrs="clr-namespace:BreadcrumbLib.Controls"
		xmlns:themes="clr-namespace:BreadcrumbLib.Themes"
    >
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/BreadcrumbLib;component/Themes/Default/ComboboxNullAsSeparatorStyle.xaml" />
    <ResourceDictionary Source="/BreadcrumbLib;component/Themes/Default/Buttons.xaml" />
    <ResourceDictionary Source="/BreadcrumbLib;component/Themes/Default/Brushes.xaml" />
	</ResourceDictionary.MergedDictionaries>

  <Style TargetType="{x:Type ctlrs:DropDown}">
		<Setter Property="Background" Value="{DynamicResource {x:Static themes:ResourceKeys.ControlBackground}}" />
		<Setter Property="BorderBrush" Value="{DynamicResource {x:Static themes:ResourceKeys.ControlBorderBrush}}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="HeaderButtonTemplate" Value="{DynamicResource BaseToggleButton}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ctlrs:DropDown}">
          <Grid>
            <ToggleButton x:Name="PART_ToggleButton"  MinWidth="16"
                          Template="{Binding HeaderButtonTemplate, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" 
                          BorderBrush="{TemplateBinding BorderBrush}" 
                          BorderThickness="{TemplateBinding BorderThickness}"  
                          HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
                          IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
              <Grid>
                <ContentPresenter Content="{TemplateBinding Header}" />
              </Grid>
            </ToggleButton>

            <Popup x:Name="PART_Popup" Focusable="False"
                    IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                    StaysOpen="False" 
                    HorizontalOffset="{TemplateBinding HorizontalOffset}"
                    VerticalOffset="{TemplateBinding VerticalOffset}"
                    Placement="{TemplateBinding Placement}" 
                    PlacementTarget="{TemplateBinding PlacementTarget}"
                               
                    PopupAnimation="Slide" AllowsTransparency="True">

              <Border BorderThickness="{TemplateBinding BorderThickness}" MinWidth="100" MinHeight="10"
                      BorderBrush="{TemplateBinding BorderBrush}" 
                      Background="{TemplateBinding Background}" Name="DropDownBorder">

                <Grid x:Name="PART_DropDown">
                  <!-- Use transparent inner border to implement padding against the outter element -->
                  <Border x:Name="PART_DropDownBorder" 
                          Background="{TemplateBinding Background}" 
                          Padding="{TemplateBinding Padding}"
                          BorderBrush="Transparent"
                          BorderThickness="{TemplateBinding BorderThickness}">
                    <ContentPresenter x:Name="PART_Content"  Content="{TemplateBinding Content}" />
                  </Border>
                </Grid>
              </Border>
            </Popup>
          </Grid>
          <ControlTemplate.Triggers>
            <!-- Show the normal arrow right button when there is nothing else defined in this Header -->
            <Trigger Property="Header" Value="{x:Null}">
              <Setter TargetName="PART_ToggleButton" Property="Template" Value="{StaticResource BasicArrowButton}" />
            </Trigger>
            <Trigger Property="Content" Value="{x:Null}">
              <Setter Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsDropDownAlignLeft" Value="True">
              <Setter TargetName="PART_Popup" Property="HorizontalOffset" Value="{Binding ActualWidth, ElementName=PART_ToggleButton}" />
              <Setter TargetName="PART_Popup" Property="VerticalOffset"   Value="{Binding ActualHeight, ElementName=PART_ToggleButton}" />
              <Setter TargetName="PART_Popup" Property="Placement" Value="Left" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>